// FriendFunctionTest.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
using namespace std;

class Date;

class FriendClassFunction
{
public:
	int gethisyear(Date &a);
	int gethismonth(Date &a);
	int gethisday(Date &a);
};

class FriendClass
{
public:
	int gethisyear(Date &a);
	int gethismonth(Date &a);
	int gethisday(Date &a);
};


class Date
{
public:
	Date();
	Date(int y, int m, int d);
	Date(Date &d);
	Date & operator + (Date &a);

	int getmyyear(){return m_year;}
	int getmymonth(){return m_month;}
	int getmyday(){return m_day;}

	friend int getyear(Date &a);
	friend int getmonth(Date &a);
	friend int getday(Date &a);

	friend Date operator + (Date &a,Date &b);

	friend int FriendClassFunction::gethisyear(Date &a);
	friend int FriendClassFunction::gethismonth(Date &a);
	friend int FriendClassFunction::gethisday(Date &a);

	friend class FriendClass;


private:
	int m_year, m_month, m_day;
};



Date::Date()
{
	m_year = 0;
	m_month = 0;
	m_day = 0;
}

Date::Date(int y,int m, int d) 
{
	m_year = y;
	m_month = m;
	m_day = d;
}

Date::Date(Date &d)
{
	m_year = d.m_year;
	m_month = d.m_month;
	m_day = d.m_day;	
}

Date & Date::operator + (Date &a)
{
	m_year += a.m_year;
	m_month +=a.m_month;
	m_day +=a.m_day;

	return *this;
}

int getyear(Date &a) 
{
	return a.m_year;
}

int getmonth(Date &a)
{
	return a.m_month;
}

int getday(Date &a)
{
	return a.m_day;
}

Date operator + (Date &a,Date &b)
{
	Date temp;
	temp.m_year = a.m_year + b.m_year;
	temp.m_month = a.m_month + b.m_month;
	temp.m_day = a.m_day +b.m_day;

	return temp;
}


int FriendClassFunction::gethisyear(Date &a)
{
	return a.m_year;
}
int FriendClassFunction::gethismonth(Date &a)
{
	return a.m_month;
}

int FriendClassFunction::gethisday(Date &a)
{
	return a.m_day;
}

int FriendClass::gethisyear(Date &a)
{
	return a.m_year;
}
int FriendClass::gethismonth(Date &a)
{
	return a.m_month;
}

int FriendClass::gethisday(Date &a)
{
	return a.m_day;
}


int main(int argc, char* argv[])
{
	Date a(2009,4,30);
	FriendClassFunction b;
	FriendClass c;

	cout<<"Member Function Example"<<endl;
	cout<<a.getmyyear()<<"-"<<a.getmymonth()<<"-"<<a.getmyday()<<endl;

	cout<<"Friend Function Example"<<endl;
	cout<<getyear(a)<<"-"<<getmonth(a)<<"-"<<getday(a)<<endl;

	cout<<"FriendClass Function Example"<<endl;
	cout<<b.gethisyear(a)<<"-"<<b.gethismonth(a)<<"-"<<b.gethisday(a)<<endl;

	cout<<"FriendClass Example"<<endl;
	cout<<c.gethisyear(a)<<"-"<<c.gethismonth(a)<<"-"<<c.gethisday(a)<<endl;

	getchar();

	return 0;
}

